# -*- coding: utf-8 -*-
from dataclasses import dataclass
import yaml
from utils.handle_request import logger

#dataclass是类在实例化过程中(调用__init__方法时给属性赋值)自动传参和自动校验的工具类


@dataclass
class CaseInfo:
    #必填
    feature: str
    name: str
    title: str
    requests: dict
    validate: dict
    #选填
    extract: dict = None
    parameties: list = None

#校验YAML格式
def verify_yaml(caseinfo: dict):
    try:
        new_case = CaseInfo(**caseinfo)
        return new_case
    except Exception:
        logger.error(caseinfo["title"]+": YAML格式不符合框架规则\n")
        #抛出异常
        raise Exception("YAML格式不符合框架规则！")

        # print("YAML格式不符合框架规则！")


if __name__ == '__main__':
    with open(r'C:\Users\27189\Desktop\工作\sem\testcases\002.yaml') as f:
        yaml_dict = yaml.safe_load(f)
        print(yaml_dict)
        print(*yaml_dict)
        #校验yaml
        verify_yaml(*yaml_dict)
        # print(type(verify_yaml(*yaml_dict)))


